package com.snow.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.snow.bean.User;
import com.snow.serviceImpl.UserServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@RestController 
public class UserController {

    @Autowired
    private UserServiceImpl userService;
    
    @ResponseBody
    @RequestMapping("/getUserLsit.htm")
    public Object getUserLsit() throws JsonProcessingException {
       List<User> userList = userService.selectAll();
       ObjectMapper maper = new ObjectMapper();
   		maper.writeValueAsString(userList);
        return userList;
    }
    
    @ResponseBody
    @RequestMapping("/getString.htm") 
    public Object getString() throws JsonProcessingException {
    	
    	JSONObject json = new JSONObject();
//    	ObjectMapper maper = new ObjectMapper();
//    	maper.writeValueAsString("Hellow World!");
    	json.put("r", "喝辣的升级反馈");
    	return json;
    }
    
    @RequestMapping("/getUser.htm")
    public Object getUser() {
       User user = userService.selectOne();
        return user;
    }
}
